﻿using UnityEngine;
using UnityEngine.UI;

public class TrashController: MonoBehaviour
{
    private float suggestorHandTimer = 10f;
    public static TrashController exemple;
    public Image toFillImage;
    public GameObject x1;
    public GameObject x2;
    public GameObject discard;
    public GameObject video;
    public GameObject suggestorHand;
    private int remainingDiscard;

    private void Awake()
    {
        TrashController.exemple = this;
    }

    private void Start()
    {
        this.remainingDiscard = 2;
        this.setItem();
    }

    public void reset()
    {
        this.suggestorHandTimer = Random.Range(15, 25);
        this.suggestorHand.SetActive(false);
    }

    private void Update()
    {
        this.suggestorHandTimer -= Time.deltaTime;
        if (this.suggestorHandTimer >= 0.0)
            return;
        if (!this.suggestorHand.activeInHierarchy && this.remainingDiscard > 0)
            this.suggestorHand.SetActive(true);
        this.suggestorHandTimer = 0.0f;
    }

    public void setItem()
    {
        if (this.remainingDiscard == 0)
        {
            this.toFillImage.fillAmount = 1f;
            this.x1.SetActive(false);
            this.x2.SetActive(false);
            this.discard.SetActive(false);
            this.video.SetActive(true);
        }
        else if (this.remainingDiscard == 1)
        {
            this.toFillImage.fillAmount = 0.503f;
            this.x1.SetActive(true);
            this.x2.SetActive(false);
            this.discard.SetActive(true);
            this.video.SetActive(false);
        }
        else
        {
            if (this.remainingDiscard == 2)
            {
                this.toFillImage.fillAmount = 0.0f;
                this.x1.SetActive(true);
                this.x2.SetActive(true);
                this.discard.SetActive(true);
                this.video.SetActive(false);
            }
        }
    }

    public void clicked()
    {
        Debug.Log(nameof(this.clicked));
        if (this.remainingDiscard > 0 /*&& Shooter.shooter.canFire*/)
        {
            this.suggestorHandTimer = Random.Range(15, 25);
            this.suggestorHand.SetActive(false);
            // GameManager.Instance.discardCurrentOne();
            --this.remainingDiscard;
            this.setItem();
        }
        else
        {
            if (PubliciteDirectore.exemple.isAmazingAdAvailable() && this.remainingDiscard == 0)
                PubliciteDirectore.exemple.yeaahhh();
        }
    }

    public void adWatched()
    {
        Debug.Log(nameof(this.adWatched));
        this.remainingDiscard = 2;
        this.setItem();
        this.suggestorHandTimer = Random.Range(20, 30);
        this.suggestorHand.SetActive(false);
    }
}